﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class TimeControl : MonoBehaviour {

    private Text timeText;

    private float time;
    public float Timer
    {
        get { return time; }
        set { time = value; }
    }

	// Use this for initialization
	void Awake () {
        timeText = transform.Find("Text").GetComponent<Text>();
        float highscore = PlayerPrefs.GetFloat("HighScore");
        if(highscore == 0)
        {
            transform.Find("Show").GetComponent<Text>().text = "最高 :   [   无   ]";
        }
        else
        {
            transform.Find("Show").GetComponent<Text>().text = "最高 : " + GetTimeText(highscore);
        }

        time = 0;
	}
	
	void Update () {
        time += Time.deltaTime;
        timeText.text = "时间 : " + GetTimeText(time);
	}

    string GetTimeText(float t)
    {
        int time_ = (int)(t * 1000);

        if (time_ > 3599990) time_ = 3599990;

        //00:00:00
        int third = time_ % 1000 / 10;
        int second = (time_ / 1000) % 60;
        int first = time_ / 60000;


        return first.ToString("D2") + " : " + second.ToString("D2") + " : " + third.ToString("D2");

    }

}
